package com.wc.acwing.思维.沿栅栏散步;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/3/14 10:18
 * @description
 * https://www.acwing.com/problem/content/5593/
 */
public class Main {
    /**
     * x, y 取值范围是 1000,
     * 所以可以使用前缀和, 操作
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010, M = 1010;
    static int[][] s = new int[M][M], q = new int[N][2];
    static int n, m;

    public static void main(String[] args) {
        m = sc.nextInt();
        n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            q[i][0] = sc.nextInt();
            q[i][1] = sc.nextInt();
        }
        int x = q[n - 1][0], y = q[n - 1][1], sum = 0;
        for (int i = 0; i < n; i++) {
            int tx = q[i][0], ty = q[i][1];
            int vx = get(x, tx), vy = get(y, ty);
            while (x != tx || y != ty) {
                x += vx;
                y += vy;
                s[x][y] = ++sum;
            }
        }
        while (m-- > 0) {
            int x1 = sc.nextInt(), y1 = sc.nextInt(), x2 = sc.nextInt(), y2 = sc.nextInt();
            int dist = Math.abs(s[x2][y2] - s[x1][y1]);
            int res = Math.min(dist, sum - dist);
            out.println(res);
        }
        out.flush();
    }

    static int get(int x, int tx) {
        if (x < tx) return 1;
        if (x > tx) return -1;
        return 0;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

